package com.cby.android.sample.adapter.binder

import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.cby.android.sample.R
import com.cby.android.sample.adapter.WeatherItemAdapter
import com.cby.android.sample.bean.roll.RollForecastsBean
import com.chad.library.adapter.base.binder.QuickItemBinder
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.yqritc.recyclerviewflexibledivider.VerticalDividerItemDecoration

/**
 * @description: 未来天气
 *
 * @author ChenBaoyang
 * @date 4/27/21 16:09
 */
class WeatherLaterItemBinder : QuickItemBinder<RollForecastsBean>() {
    override fun convert(holder: BaseViewHolder, data: RollForecastsBean) {
        

        //初始化RecycleView
        val recyclerView = holder.getView<RecyclerView>(R.id.recycle_later)
        val linearLayoutManager = LinearLayoutManager(
                context, LinearLayoutManager.HORIZONTAL, false)
        recyclerView.layoutManager = linearLayoutManager
        recyclerView.itemAnimator = DefaultItemAnimator()
        recyclerView.addItemDecoration(
            VerticalDividerItemDecoration.Builder(
                context
            ).color(context.resources.getColor(R.color.color_white_cccccc)).build()
        )
        if (data.forecasts.size > 0) {
            val weather2Adapter = WeatherItemAdapter()
            recyclerView.adapter = weather2Adapter
            weather2Adapter.setList(data.forecasts)
        }
    }

    override fun getLayoutId() = R.layout.item_weather_later
}